<template>
  <div class="mod-study__base">
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <el-form-item label="模糊搜索">
        <el-input v-model="state.dataForm.keywords" placeholder="请输入" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="state.getDataList()">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="state.hasPermission('study:dept:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" row-key="id" border style="width: 100%">
      <el-table-column prop="name" label="基地" header-align="center"></el-table-column>
      <el-table-column prop="address" label="地址" header-align="center"></el-table-column>
      <el-table-column label="操作" fixed="right" header-align="center" align="center">
        <template v-slot="scope">
          <el-button v-if="state.hasPermission('study:dept:update')" type="primary" link @click="addOrUpdateHandle(scope.row)">修改</el-button>
          <el-button v-if="state.hasPermission('study:dept:delete')" type="primary" link @click="state.deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script lang="ts" setup>
import { reactive, ref, toRefs } from "vue";
import useView from "@/hooks/useView";
import { useRouter } from "vue-router";

const router = useRouter();
const view = reactive({
  getDataListURL: "/study/dept/page",
  getDataListIsPage: true,
  deleteURL: "/study/dept/del",
  deleteIsBatch: true,
  deleteIsPost: true,
  dataForm: {
    keywords: "",
    type: "BASE"
  }
});

const state = reactive({ ...useView(view), ...toRefs(view) });

const addOrUpdateHandle = (row?: any) => {
  router.push({
    path: '/study/base/edit',
    query: {
      row: JSON.stringify(row)
    },
  });
};
</script>
